package 剑指offer.Month7_07.day14;

public class 整数中1出现的次数 {
    public int NumberOf1Between1AndN_Solution(int n) {
        StringBuilder s = new StringBuilder();
        for (int i = 1; i <= n; i++) {
            s.append(i);
        }
        char[] arr = s.toString().toCharArray();
        int count = 0;
        for (int i = 0; i < arr.length; i++) {
            if(arr[i] == '1'){
                count++;
            }
        }
        return count;
    }
}
